<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>个人理财系统</title>
    <!-- 引入bootstrap样式 -->
    <link th:href="@{/bootstrap/css/bootstrap.css}" rel="stylesheet" type="text/css">
    <!--图标库-->
    <link th:href="@{/lyear/css/materialdesignicons.min.css}" rel="stylesheet" type="text/css"/>
    <!--弹出框样式-->
    <link th:href="@{/lyear/jconfirm/jquery-confirm.min.css}" rel="stylesheet" type="text/css"/>
    <!--自定义样式-->
    <link href="../lyear/css/style.min.css" th:href="@{/lyear/css/style.min.css}" rel="stylesheet" type="text/css"/>

</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="user/common/leftbar::#leftbaraside"></div>
        <!--头部信息-->
        <div th:replace="user/common/topbar::#topbarheader"></div>

        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h4>我的消息</h4>
                            </div>
                            <div th:if="${!infoList.isEmpty()}" class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-hover table-striped">
                                        <thead>
                                        <tr>
                                            <th class="info">序号</th>
                                            <th class="info">消息标题</th>
                                            <th class="info">消息内容</th>
                                            <th class="info">发送人</th>
                                            <th class="info">发送时间</th>
                                            <th class="info">状态</th>
                                            <th class="info">相关操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr th:each="info:${infoList}">
                                            <td th:text="${(infoPageInfo.pageNum - 1) * infoPageInfo.pageSize+infoStat.index+1}"></td>
                                            <td th:text="${info.title}"></td>
                                            <td th:text="${info.infodesc}"></td>
                                            <td th:text="${info.admin.username}"></td>
                                            <td th:text="${#dates.format(info.createtime, 'yyyy-MM-dd')}"></td>
                                            <td th:if="${info.status==0}" th:text="未读"></td>
                                            <td th:if="${info.status==1}" th:text="已读"></td>
                                            <td>
                                                <button th:if="${info.status==1}" >
															<span class="glyphicon glyphicon-pencil"
                                                                  ></span> 已读
                                                </button>
                                                <button th:if="${info.status==0}" class="btn btn-primary btn-sm edit_btn"
                                                        th:attr="edit-id=${info.id}">
															<span class="glyphicon glyphicon-pencil"
                                                                  aria-hidden="true"></span> 已读
                                                </button>

                                                <button class="btn btn-danger btn-sm delete_btn"
                                                        th:attr="delete-id=${info.id},title=${info.title}">
															<span class="glyphicon glyphicon-trash"
                                                                  aria-hidden="true"></span> 删除
                                                </button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>

                                <!-- 显示分页信息 -->
                                <div class="row">

                                    <div class="col-md-5 col-md-offset-1">
                                        <div class="btn-group">
                                            <button class="btn btn-default">
                                                <span>页次：</span>
                                            </button>
                                            <button class="btn btn-default">
                                                <span th:text="${infoPageInfo.pageNum}+'/'+${infoPageInfo.pages}+'页'"></span>
                                            </button>
                                            <button class="btn btn-default">
                                                <span>每页显示：</span>
                                            </button>
                                            <div class="btn-group">
                                                <button id="btnGroupDrop1"
                                                        class="btn btn-default dropdown-toggle"
                                                        data-toggle="dropdown" aria-haspopup="true"
                                                        aria-expanded="false"><span
                                                        th:text="${infoPageInfo.pageSize}"></span>
                                                    <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu">
                                                    <li th:each="i:${#numbers.sequence(1,10)}"><a th:text="${i}"
                                                                                                  th:href="@{/user/personal/toMyInfo.html(pageNum=${infoPageInfo.pageNum},pageSize=${i})}"></a>
                                                    </li>
                                                </ul>
                                            </div>
                                            <button class="btn btn-default">
                                                <span>条</span>
                                            </button>
                                            <button class="btn btn-default">
                                                <span>总记录数：</span>
                                            </button>
                                            <button class="btn btn-default">
                                                <span th:text="${infoPageInfo.total}+'条'"></span>
                                            </button>
                                        </div>
                                    </div>

                                    <!-- 分页条信息 -->
                                    <div class="col-md-5">
                                        <nav aria-label="Page navigation">
                                            <ul class="pagination pagination-lg pull-right"
                                                style="margin-top: 0">
                                                <li>
                                                    <a th:href="@{/user/personal/toMyInfo.html(pageNum=1,pageSize=${infoPageInfo.pageSize})}">首页</a>
                                                </li>

                                                <li th:if="${infoPageInfo.hasPreviousPage }"><a
                                                        th:href="@{/user/personal/toMyInfo.html(pageNum=${infoPageInfo.pageNum}-1,pageSize=${infoPageInfo.pageSize})}"
                                                        aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                                                </a></li>

                                                <li th:each="page_Num:${infoPageInfo.navigatepageNums }"
                                                    th:class="${page_Num == infoPageInfo.pageNum?'active':''}">
                                                    <a th:if="${page_Num == infoPageInfo.pageNum}"
                                                       th:text="${page_Num}"
                                                       th:href="@{#}">
                                                    </a>
                                                    <a th:text="${page_Num}"
                                                       th:if="${page_Num != infoPageInfo.pageNum}"
                                                       th:href="@{/user/personal/toMyInfo.html(pageNum=${page_Num},pageSize=${infoPageInfo.pageSize})}">
                                                    </a>
                                                </li>

                                                <li th:if="${infoPageInfo.hasNextPage }"><a
                                                        th:href="@{/user/personal/toMyInfo.html(pageNum=${infoPageInfo.pageNum}+1,pageSize=${infoPageInfo.pageSize})}"
                                                        aria-label="Next"> <span aria-hidden="true">&raquo;</span>
                                                </a></li>

                                                <li><a
                                                        th:href="@{/user/personal/toMyInfo.html(pageNum=${infoPageInfo.pages},pageSize=${infoPageInfo.pageSize})}">末页</a>
                                                </li>
                                            </ul>
                                        </nav>
                                    </div>
                                </div>
                            </div>

                            <div th:if="${infoList.isEmpty()}" class="card-body">
                                <div class="table-responsive">
                                    <h4>很抱歉！暂时还没有收到您的消息</h4>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<!-- 引入jQuery和bootstrap的js -->
<script th:src="@{/js/jquery.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap.js}"></script>
<!--滚动条插件-->
<script th:src="@{/lyear/js/perfect-scrollbar.min.js}"></script>
<!--弹出框js-->
<script th:src="@{/lyear/jconfirm/jquery-confirm.min.js}"></script>
<!--自定义js脚本-->
<script th:src="@{/lyear/js/main.min.js}"></script>
<script type="text/javascript">

    //已读
    $(document).on("click", ".edit_btn", function () {
        var infoId = $(this).attr("edit-id");
        $.ajax({
            url: "/user/updateInfo/" + infoId,
            type: "put",
            success: function (result) {
                if (result.code === 100) {
                    location.href = "/user/personal/toMyInfo.html";
                }else {
                    $.alert('读取失败!');
                }
            }
        });
    });

    //删除
    $(document).on("click", ".delete_btn", function () {
        var infoId = $(this).attr("delete-id");
        var title = $(this).attr("title");
        $.alert({
            title: '提示：',
            content: "确定删除 <strong>"+title+"</strong> 吗？",
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function(){
                        $.ajax({
                            url: "/user/deleteInfo/" + infoId,
                            type: "DELETE",
                            success: function (result) {
                                if (result.code === 100) {
                                    location.href = "/user/personal/toMyInfo.html";
                                }else {
                                    $.alert('删除失败!');
                                }
                            }
                        });
                    }
                },
                cancel: {
                    text: '取消',
                    action: function () {
                        $.alert('已取消!');
                    }
                }
            }
        });
    })

</script>
</body>
</html>
